让命令历史永久保存并加时间戳

1
2
3
4
5
6
7
8
#!/bin/sh
grep HISTTIMEFORMAT /etc/bashrc || echo 'export HISTTIMEFORMAT="%Y-%m-%d %H:%M:%S "' >>/etc/bashrc
for U in `grep -v shutdown /etc/passwd|awk -F: '$NF~/sh/&&$NF!~/no/{print $1}'`
do
UHOME=`cat /etc/passwd|grep "^$U"|cut -d: -f6`
[ ! -f $UHOME/.bash_history ] && touch $UHOME/.bash_history
chattr +a $UHOME/.bash_history
done